
$(function() {
	CollectApp.reload(0);
});
var CollectApp = function(){
	var pageSize = 10; //每页显示条数初始化，修改显示条数，修改这里即可
	var pCount = 0;
	var pagecur=0;
	return{
		del:function(){

			if(CollectApp.getCheck()==null||CollectApp.getCheck()==''){
				layer.open({
						    content: '您尚未选择任何选项！',
						    skin: 'msg',
						    time: 2 //2秒后自动关闭
						});
				return false;
			}
			layer.open({
			    content: '您确定要删除收藏商品吗？'
			    ,btn: ['删除', '返回']
			    ,yes: function(index){
			     	var url = $("#APP_ROOT_PATH").val() + "collect/bitchdelete";
						param = {
							"ids":CollectApp.getCheck()
						};

					mui.util.Ajax.asyncGET(url, param, function(data) {
						if(data==true){
							
							CollectApp.reload(0);
						}else{
							layer.open({
								    content: data.message,
								    skin: 'msg',
								    time: 2 //2秒后自动关闭
							});
						}
					});
					 layer.close(index);
			    }
			    
			  });
		
		},
		reload: function(page) {
			pagecur = page;
			var url = $("#APP_ROOT_PATH").val() + "collect/page_data";

			
				param = {
					"page": page + 1,
					"pageSize": pageSize
				};

			mui.util.Ajax.asyncGET(url, param, function(data) {
				pCount = data.total;
				var json = {
					"data": data.rows,
					"ossPath": mui.util.Enum.OSS_PATH
				};
				var bt = baidu.template;
				var htmlStr = bt('t:goodsList', json);
					$(".goods_list").html(htmlStr);
				if(pCount > 0) {
					$("#Pagination").pagination(pCount, {
						callback: CollectApp.reload,
						prev_text: "« 上一页",
						next_text: "下一页 »",
						items_per_page: pageSize,
						num_edge_entries: 2,
						num_display_entries: 6,
						current_page: page
					});
				} else {
					$("#Pagination").html("");
				}
				layer.closeAll();
				CollectApp.bindEvent();
			});
		},
		//获取选择的按钮
		getCheck: function() {
			var collectList = "";
			$(".collect_select:checked").each(function() {
				collectList += $(this).val() + ",";
			})
			if(collectList != "") {
				return collectList.substring(0, collectList.length - 1);
			}
			return "";
		},
		bindEvent:function(){
			//绑定选择按钮
			$(".u4-input").click(function(){
			    if($(this).children("div").hasClass("unchecked")){
			        $(this).children("div").addClass("on-checked").removeClass("unchecked");
			        $(this).find(".collect_select").attr("checked",true);
			    }else{
			    	$(this).children("div").addClass("unchecked").removeClass("on-checked");
			    	 $(this).find(".collect_select").attr("checked",false);
			    }
			});
//			$(".u4-input").click(function(){
//				    if($(this).hasClass("on-checked")){
//				        $(this).removeClass("on-checked");
//				        $(this).find(".collect_select").attr("checked","false")
//				    }else{
//				        $(this).addClass("on-checked");
//				         $(this).find(".collect_select").attr("checked","true")
//				    }
//			});
		}
	}
}();